package com.test.schoolhelper.ui.activity;

import android.app.LocalActivityManager;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.SimpleAdapter;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.test.schoolhelper.R;
import com.test.schoolhelper.base.BaseActivity;
import com.test.schoolhelper.databinding.ActivityContainerBinding;
import com.test.schoolhelper.databinding.ActivityHomeBinding;
import com.test.schoolhelper.ui.fragment.NewsFragment;
import com.test.schoolhelper.ui.fragment.WeatherFragment;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * create by 20303 on 2024/6/9
 */
public class HomeActivity extends BaseActivity<ActivityHomeBinding> {
    private List<Map<String,Object>> mapList;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        SimpleAdapter adapter = new SimpleAdapter(this,mapList,R.layout.item_home_grid,new String[]{
                "img",
                "title"
        },new int[]{
                R.id.img,
                R.id.title
        });
        getBinding().gridView.setAdapter(adapter);
        getBinding().gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                if (i != mapList.size() - 1){
                    Map<String,Object> map = mapList.get(i);
                    Intent intent = new Intent(HomeActivity.this,ContainerActivity.class);
                    intent.putExtra("isActivity", (Boolean) map.get("isActivity"));
                    intent.putExtra("className", (String) map.get("className"));
                    startActivity(intent);
                }else {
                    Toast.makeText(HomeActivity.this,"敬请期待！",Toast.LENGTH_SHORT).show();
                }
            }
        });
    }

    @Override
    protected void initData() {
        mapList = new ArrayList<>();

        Map<String,Object> map = new HashMap<>();
        map.put("img",R.drawable.weather);
        map.put("title","天气");
        map.put("isActivity",false);
        map.put("className",WeatherFragment.class.getName());
        mapList.add(map);

        map = new HashMap<>();
        map.put("img",R.drawable.newspaper);
        map.put("title","新闻");
        map.put("isActivity",false);
        map.put("className",NewsFragment.class.getName());
        mapList.add(map);

        map = new HashMap<>();
        map.put("img",R.drawable.music);
        map.put("title","音乐");
        map.put("isActivity",true);
        map.put("className",MusicActivity.class.getName());
        mapList.add(map);

        map = new HashMap<>();
        map.put("img",R.drawable.schedule);
        map.put("title","日程");
        map.put("isActivity",true);
        map.put("className",AddScheduleActivity.class.getName());
        mapList.add(map);


        map = new HashMap<>();
        map.put("img",R.drawable.alarm);
        map.put("title","闹钟");
        map.put("isActivity",true);
        map.put("className",AddAlarmActivity.class.getName());
        mapList.add(map);


        map = new HashMap<>();
        map.put("img",R.drawable.contact);
        map.put("title","电话簿");
        map.put("isActivity",true);
        map.put("className",UserActivity.class.getName());
        mapList.add(map);


        map = new HashMap<>();
        map.put("img",R.drawable.calculator);
        map.put("title","计算器");
        map.put("isActivity",true);
        map.put("className",CalculatorActivity.class.getName());
        mapList.add(map);


        map = new HashMap<>();
        map.put("img",R.mipmap.ic_launcher);
        map.put("title","更多");
        mapList.add(map);



    }

    @Override
    protected int initLayout() {
        return R.layout.activity_home;
    }

    @Override
    protected ActivityHomeBinding onCreateViewBinding(@NonNull LayoutInflater layoutInflater) {
        return ActivityHomeBinding.inflate(layoutInflater);
    }
    
}
